home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / disk / diskReceiveQ.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  4.0 KB  |  154 lines

  1. /*
  2.  *   $RCSfile: diskReceiveQ.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:55:38 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37. #include "queue_consist.h"
  38. #include "sysdefs.h"
  39. #include "ess.h"
  40. #include "checking.h"
  41. #include "trace.h"
  42. #include "error.h"
  43. #include "list.h"
  44. #include "tid.h"
  45. #include "io.h"
  46. #include "lock.h"
  47. #include "object.h"
  48. #include "msgdefs.h"
  49. #include "disk.h"
  50. #include "thread.h"
  51. #include "semaphore.h"
  52. #include "latch.h"
  53. #include "link.h"
  54. #include "bf.h"
  55. #include "pool.h"
  56. #include "volume.h"
  57. #include "threadstate.h"
  58. #include "disk_funcs.h"
  59. #include "thread_funcs.h"
  60. #include "thread_globals.h"
  61. #include "sharedmem_globals.h"
  62. #include "queue_globals.h"
  63. #include "io_globals.h"
  64.  
  65.  
  66.  void
  67. diskReceiveQ (
  68.     QUEUEPAIR    *qp,
  69.     BOOL        holdingMutex
  70. )
  71. {
  72.     extern int            disk_requests_out;
  73.     register DISKMSG    *diskMessage;
  74.     register TCB        *tcb;
  75.     ShmOffset             smindex;
  76.  
  77.     TRACE(TR_MSG|TR_DISK, TR_LEVEL_1); 
  78.  
  79.     /* dequeue the index */
  80.     if( !holdingMutex )
  81.         getMutex(&(qp->fromDisk.mutex));
  82.     if (!deq_from(qp, smindex)) {
  83.         giveMutex(&(qp->fromDisk.mutex));
  84.         return;
  85.     }
  86.     giveMutex(&(qp->fromDisk.mutex));
  87.     disk_requests_out--;
  88.  
  89.     /*
  90.      *    get a pointer to the message field
  91.      *  The message was sent by another thread (another thread->diskMessage)
  92.      *  My thread->diskMessage would point to the wrong place, so we
  93.      *  just get the proper message index from the queue.
  94.      */
  95.     diskMessage = ShmOffsetToAddress(smindex, DISKMSG);
  96.  
  97.     /*
  98.      *    get a pointer to the waiting tcb
  99.      */
  100.     TRPRINT(TR_DISK, TR_LEVEL_1, 
  101.         ("reply for thread:%d", diskMessage->body.threadId));
  102.  
  103.     tcb = &Tcbs[diskMessage->body.threadId];
  104.     CHECK_TCB_MAGIC(tcb);
  105.  
  106.     /*
  107.      *    check to see that the thread is in wait
  108.      *  with state == "waiting for disk results"
  109.      */
  110.     SM_ASSERT(LEVEL_1, tcb->state == THREAD_DISK_WAIT);
  111.     
  112.     SM_ASSERT(LEVEL_1, 
  113.         tcb->diskMessage->body.volid == diskMessage->body.volid);
  114.     /*
  115.      *    check the message magic number
  116.      */
  117.     if (diskMessage->diskmagic != DISK_MESSAGE_MAGIC)    {
  118.  
  119.         /*
  120.          *    copy in the result
  121.          */
  122.         tcb->error = esmFAILURE;
  123.         tcb->errno = esmBADMESSAGEMAGIC;
  124.         TRPRINT(TR_DISK, TR_LEVEL_1, ("error:%d errno:%d",
  125.                 tcb->error, tcb->errno));
  126.  
  127.     } else {
  128.  
  129.         /*
  130.          *    copy in the result
  131.          */
  132.         if (diskMessage->header.params.out.errno == esmNOERROR) {
  133.             tcb->error = esmNOERROR;
  134.         } else {
  135.             tcb->error = esmFAILURE;
  136.         }
  137.         tcb->errno = (int)diskMessage->header.params.out.errno;
  138.         TRPRINT(TR_DISK, TR_LEVEL_1, ("error:%d errno:%d",
  139.                 tcb->error, tcb->errno));
  140.     }
  141.  
  142.     /*
  143.      *    put the thread on the ready queue
  144.      *  like notify(&(diskGivingResults), noerror, noerror)
  145.      *  but we move the first thread only.
  146.      */
  147.     listMoveEnq( &ReadyList, &(tcb->controlList) );
  148.  
  149.     /*
  150.      * restart this thread
  151.      */
  152.     threadRestart();
  153. }
  154.